package org.meb.conquest.web.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value = "baseTextConverter")
public class BaseTextConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		return null;
	}

	@Override
	public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
		String textValue;
		if (value == null) {
			textValue = null;
		} else if (value instanceof String) {
			textValue = (String) value;
			textValue = "<p>" + textValue.trim().replaceAll("\\n+", "</p><p>") + "</p>";
			textValue = textValue.replace("<p>", "<p style=\"text-align: justify;\">");
		} else {
			textValue = value.toString();
		}
		return textValue;
	}
}
